{extend name="admin@index_layout"/}
{block name="main"}
<div class="layui-card">
    <div class="layui-card-header">钩子管理</div>
    <div class="layui-card-body">
        <table class="layui-hide" id="dataTable" lay-filter="dataTable"></table>
    </div>
</div>
<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <a class="layui-btn layui-btn-sm layui-btn-danger confirm layui-batch-all" data-href='{:url("deleteHook")}'>批量删除</a>
        <a class="layui-btn layui-btn-sm layui-iframe" href="{:url('addons/addons/addHook')}">新增钩子</a>
    </div>
</script>
<script type="text/html" id="barTool">
    <a href='{:url("editHook")}?id={{ d.id }}' class="layui-btn layui-btn-xs layui-iframe">编辑</a>
    <a href='{:url("deleteHook")}?ids={{ d.id }}' class="layui-btn layui-btn-danger layui-btn-xs layui-tr-del">删除</a>
</script>
<script type="text/html" id="statusTpl">
    <input type="checkbox" name="status" value="{{d.id}}" data-href="{:url('setHookStatus')}?id={{d.id}}" lay-skin="switch" lay-text="启用|禁用" lay-filter="switchStatus" {{ d.status==1 ? 'checked' : '' }}>
</script>
<script>
    var options = {
        id: 'dataTable',
        formId: 'searchForm',
        toolbar: '#toolbarDemo',
        url: '{:url("hooks")}',
        page: false,   //分页设置
        sortOrder: '', //排序方式  asc: 升序、desc: 降序、null: 默认排序
        cols: [
            [
                { type: 'checkbox', fixed: 'left' },
                { field: 'id', width: 80, title: 'ID' },
                { field: 'name', width: 150, title: '名称' },
                { field: 'description', title: '描述' },
                { field: 'type_text', width: 90, title: '类型' },
                { field: 'status', width: 120, align: "center", title: '状态', templet: '#statusTpl', unresize: true },
                { fixed: 'right', width: 150, title: '操作', toolbar: '#barTool' }
            ]
        ],
        done: function(res, curr, count){}, //表格数据渲染完的回调
    };
    // 搜索
    options.searchParams = function(){
        var formData = $.table._searchFormData();
        var data = {};
        data = $.extend(formData, data);
        return data;
    };
    // 单元格编辑
    options.editTable = function(field, value, data) {
        // 参数说明：  field: 当前编辑的字段名, value: 得到修改后的值, data: 所在行的所有相关数据
    };
    // 加载layui表格
    $.table.init(options);
</script>
{/block}